var app = getApp();

Page({
  data: {
    isLoading: false,
    isPopUp: true,
    feedId: 0,
    status: 0,
    ifEditHrTest: 0,
    selectList: [
      { id: 0, value: '非常满意' },
      { id: 1, value: '满意' },
      { id: 2, value: '一般' },
      { id: 3, value: '不满意' },
      { id: 4, value: '很不满意' }
    ],
    suggestion: '',
    playScore: '',
    isChild: false,
    isDisabled: false
  },
  onLoad: function (opt) {
    wx.showLoading({
      title: '加载中',
    });
    this.setData({
      feedId: opt.id,
      status: opt.status,
      isChild: wx.getStorageSync("isChild")
    })
    // if (opt.status == 1) {
    //   this.getDetail(opt.id);
    // }
    this.getDetail(opt.id);
  },
  // 获取详情
  getDetail: function (id) {
    var that = this;
    wx.request({
      url: app.globalData.apiBaseUrl + '/trackBack/selectUserBackInfo',
      header: {
        'content-type': 'application/x-www-form-urlencoded; charset=utf-8',
        'FilterToken_MT': wx.getStorageSync("token")
      },
      method: 'GET',
      data: {
        id: id
      },
      dataType: 'json',
      success: function (msg) {
        msg = msg.data;
        if (msg.code == 200) {
          if (msg.data.status == 1) {
            var serviceStatisfied = Number(msg.data.serviceStatisfied);
            var serviceStatisfiedList = that.data.selectList.map((item, index) => {
              if (item.id == serviceStatisfied) item.checked = 'true'
              return item
            })
            that.setData({
              selectList: serviceStatisfiedList,
              playScore: msg.data.playScore,
              suggestion: msg.data.suggestion,
              ifEditHrTest: msg.data.ifEditHrTest,
              feedId: msg.data.id,
              status: msg.data.status
            });
          }
          that.setData({
            isLoading: true
          });
          wx.hideLoading();
        } else {
          wx.hideLoading();
          wx.showToast({
            title: msg.msg,
            icon: 'none',
            duration: 3000
          })
        }
      }
    })
  },
  // 提交表单-问卷调查
  formSubmitInv: function (e) {
    var that = this;
    var formObj = e.detail.value;
    formObj.id = this.data.feedId;

    if (formObj.serviceStatisfied != '' && formObj.playScore != '' && formObj.suggestion != '') {
      that.setData({
        isDisabled: true
      });
      wx.request({
        url: app.globalData.apiBaseUrl + '/trackBack/addUserBackInfo',
        header: {
          'content-type': 'application/json;charset=UTF-8',
          'FilterToken_MT': wx.getStorageSync("token")
        },
        method: 'POST',
        dataType: 'json',
        data: formObj,
        success: function (res) {
          res = res.data;
          if (res.code == 200) {
            that.setData({
              isPopUp: false
            })
          } else {
            wx.showToast({
              title: res.msg,
              icon: 'none',
              duration: 3000
            });
            that.setData({
              isDisabled: false
            })
          }
        }
      })
    } else {
      wx.showToast({
        title: '请完善填写信息',
        icon: 'none',
        duration: 3000
      })
    }
  },
  // 打开PHBQ页面
  openPHBQ: function() {
    var that = this;
    this.setData({
      isPopUp: true
    })
    wx.redirectTo({
      url: "../phbq/phbq?feedId=" + that.data.feedId
    })
  },
  // 关闭弹窗
  closePopUp: function () {
    this.setData({
      isPopUp: true
    })
    wx.navigateBack({
      delta: 2
    })
  }
})